wxapp.logic.networkLogin = {
    SESSION_KEY: "TU_SESSION_STORAGE",
    _loginCount: 0,
    login: function() {
        this._loginCount >= 1 ? tywx.NotificationCenter.trigger(tywx.EventType.SDK_LOGIN_SUCCESS) : (this.getSystemInfo(), 
        this.wxLogin());
    },
    loginGuest: function() {
        tywx.SystemInfo.wxAppId = "wx6ac3f5090a6b99c5", this.getSystemInfo(), this.guestLogin();
    },
    wxLogin: function() {
        var t = this;
        wxapp.tools.bilog.clickStat(tywx.clickStatEventType.clickStatEventTypeWxLoginStart, []), 
        wx.login({
            success: function(e) {
                if (wxapp.tools.bilog.clickStat(tywx.clickStatEventType.clickStatEventTypeWxLoginSuccess, [ e.code ]), 
                e.code) {
                    var n = e.code;
                    t.tyLogin(n, {}), tywx.NotificationCenter.trigger(tywx.EventType.WEIXIN_LOGIN_SUCCESS);
                } else tywx.NotificationCenter.trigger(tywx.EventType.WEIXIN_LOGIN_FAIL);
            },
            fail: function(t) {
                wxapp.tools.bilog.clickStat(tywx.clickStatEventType.clickStatEventTypeWxLoginFailed, []), 
                tywx.NotificationCenter.trigger(tywx.EventType.WEIXIN_LOGIN_FAIL);
            },
            complete: function(t) {}
        });
    },
    guestLogin: function() {
        var t = this;
        wx.login({
            success: function(e) {
                t.tyLogin(e.code, {}), tywx.NotificationCenter.trigger(tywx.EventType.WEIXIN_LOGIN_SUCCESS);
            },
            fail: function(t) {
                tywx.NotificationCenter.trigger(tywx.EventType.WEIXIN_LOGIN_FAIL);
            }
        });
    },
    tyLogin: function(t, e) {
        var n = this;
        wx.showShareMenu({
            withShareTicket: !0
        }), "{}" == JSON.stringify(e) && (e.nickName = wxapp.appData.wxUserInfo.nickName, 
        e.avatarUrl = wxapp.appData.wxUserInfo.avatarUrl, e.gender = wxapp.appData.wxUserInfo.gender), 
        wx.getUserInfo({
            lang: "zh_CN",
            withCredentials: !0,
            success: function(t) {
                wxapp.appData.wxUserInfo.iv = t.iv, wxapp.appData.wxUserInfo.encryptedData = t.encryptedData;
            },
            fail: function(t) {}
        });
        var i = e.gender || 0, o = tywx.Util.getLocalUUID(), a = tywx.SystemInfo.loginUrl + "open/v6/user/LoginBySnsIdNoVerify", r = {
            "content-type": "application/x-www-form-urlencoded"
        };
        wxapp.tools.bilog.clickStat(tywx.clickStatEventType.clickStatEventTypeLoginSDKStart, [ t, o, e.nickName ]);
        var c = {
            appId: tywx.SystemInfo.appId,
            wxAppId: tywx.SystemInfo.wxAppId,
            clientId: tywx.SystemInfo.clientId,
            snsId: "wxapp:" + t,
            uuid: o,
            nickName: e.nickName,
            avatarUrl: e.avatarUrl,
            gender: i,
            scene_id: tywx.UserInfo.scene_id || "",
            scene_param: tywx.UserInfo.scene_param || "",
            invite_id: tywx.UserInfo.invite_id || 0,
            iv: wxapp.appData.wxUserInfo.iv || "",
            encryptedData: wxapp.appData.wxUserInfo.encryptedData || ""
        };
        wx.request({
            url: a,
            header: r,
            data: c,
            method: "POST",
            success: function(i) {
                try {
                    var a = i.data;
                    if (a.error && 1 == a.error.code) return void console.log("tuyoo login fail...");
                    a.result && a.result.info && wx.showModal({
                        content: a.result.info,
                        showCancel: !1,
                        confirmText: "确定"
                    });
                    var r = a.result;
                    tywx.UserInfo.userId = r.userId, tywx.UserInfo.userName = r.userName, tywx.UserInfo.userPic = r.purl, 
                    tywx.UserInfo.authorCode = r.authorCode, tywx.UserInfo.wxgame_session_key = r.wxgame_session_key;
                    var c = r.token;
                    wxapp.twarn("net", "token:" + c), wx.setStorage({
                        key: n.SESSION_KEY,
                        data: c
                    }), n.uploadWxEncryptedData(r), wxapp.tools.bilog.clickStat(tywx.clickStatEventType.clickStatEventTypeLoginSDKSuccess, [ t, o, e.nickName, r.userId ]), 
                    tywx.showScene && tywx.showQuery && tywx.showQuery.sourceCode && tywx.BiLog.clickStat(tywx.clickStatEventType.clickStatEventTypeUserFrom, [ tywx.showScene, tywx.showQuery.inviteCode, tywx.showQuery.sourceCode, tywx.showQuery.imageType, "GameStart" ]), 
                    n.initWebSocketUrl(r), n._loginCount++, tywx.NotificationCenter.trigger(tywx.EventType.SDK_LOGIN_SUCCESS);
                } catch (t) {
                    tywx.NotificationCenter.trigger(tywx.EventType.SDK_LOGIN_FAIL);
                }
            },
            fail: function(n) {
                wxapp.tools.bilog.clickStat(tywx.clickStatEventType.clickStatEventTypeLoginSDKFailed, [ t, o, e.nickName ]), 
                tywx.NotificationCenter.trigger(tywx.EventType.SDK_LOGIN_FAIL);
            },
            complete: function(t) {}
        });
    },
    uploadWxEncryptedData: function(t) {
        wx.getUserInfo({
            lang: "zh_CN",
            withCredentials: !0,
            success: function(e) {
                var n = tywx.SystemInfo.loginUrl + "open/v6/user/setWxEncryptedData", i = {
                    "content-type": "application/x-www-form-urlencoded"
                }, o = {
                    userId: t.userId,
                    wxAppId: tywx.SystemInfo.wxAppId,
                    iv: e.iv || "",
                    encryptedData: e.encryptedData || ""
                };
                wx.request({
                    url: n,
                    header: i,
                    data: o,
                    method: "POST",
                    success: function(t) {},
                    fail: function(t) {}
                });
            },
            fail: function(t) {}
        });
    },
    initWebSocketUrl: function(t) {
        if (t && t.tcpsrv) {
            var e, n = t.tcpsrv.ip, i = t.tcpsrv.wsport || t.tcpsrv.port;
            e = tywx.SystemInfo.loginUrl.indexOf("https://") > -1 ? "wss://" + n + "/" : "ws://" + n + ":" + i.toString() + "/", 
            tywx.SystemInfo.webSocketUrl = e;
        }
    },
    getSystemInfo: function() {
        wx.getSystemInfo({
            success: function(t) {
                var e = t.model.indexOf("iPhone") >= 0, n = t.windowHeight, i = 0;
                i = e ? 812 == n ? 2 : 736 == n ? 4 : 1 : 3, tywx.UserInfo.systemType = i, tywx.UserInfo.wechatType = t.version, 
                tywx.UserInfo.model = t.model, tywx.UserInfo.system = t.system, tywx.UserInfo.sdkVersion = t.SDKVersion, 
                tywx.BiLog.clickStat(tywx.clickStatEventType.clickStatEventTypeSubmitVersionInfo, [ t.version, t.SDKVersion, t.platform, t.system ]), 
                tywx.SystemInfo.windowHeight = t.windowHeight, tywx.SystemInfo.windowWidth = t.windowWidth;
            },
            fail: function() {},
            complete: function() {}
        });
    },
    reLogin: function() {}
};